home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Http Server / •OT_Classes / TNetworkEventHandler.cp < prev    next >
Encoding:
Text File  |  1996-01-11  |  3.0 KB  |  102 lines  |  [TEXT/CWIE]

  1. //    TNetworkEventHandler.cp - Macintosh OpenTransport network class object
  2. // 
  3. // Apple Macintosh Developer Technical Support
  4. // Written by:  Vinne Moscaritolo
  5. //
  6. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  7. //
  8. // You may incorporate this sample code into your applications without
  9. // restriction, though the sample code has been provided "AS IS" and the
  10. // responsibility for its operation is 100% yours.  However, what you are
  11. // not permitted to do is to redistribute the source as "DSC Sample Code"
  12. // after having made changes. If you're going to re-distribute the source,
  13. // we require that you make it clear in the source that the code was
  14. // descended from Apple Sample Code, but that you've made changes.
  15. // 
  16.  
  17. #include "TNetworkEventHandler.h"
  18.  
  19.  
  20. // ---------------------------------------------------------------------------
  21. //     TNetworkEventHandler::fgActiveList
  22. // ---------------------------------------------------------------------------
  23. //    List of active TNetworkEventHandler objects
  24. //
  25. TList     TNetworkEventHandler::fgActiveList; 
  26.  
  27.  
  28. // ---------------------------------------------------------------------------
  29. //     TNetworkEventHandler
  30. // ---------------------------------------------------------------------------
  31. //    Default Constructor
  32.  
  33. TNetworkEventHandler::TNetworkEventHandler()
  34. {
  35.  
  36. // add this to the end list of network event handlers   
  37.     fgActiveList.Append(this);
  38. }
  39.  
  40. // ---------------------------------------------------------------------------
  41. //     ~TNetworkEventHandler
  42. // ---------------------------------------------------------------------------
  43. //    Destructor
  44.  
  45. TNetworkEventHandler::~TNetworkEventHandler()
  46. {
  47.     TNetworkEvent*    aEvent;
  48.  
  49. // dispose of any outstanding events..
  50.     while( aEvent = (TNetworkEvent*) fEventQueue.Dequeue() ) 
  51.             delete aEvent;
  52.  
  53. // remove this from list of network event handlers  
  54.     fgActiveList.Remove(this);
  55.  
  56. };
  57.  
  58.  
  59. // ---------------------------------------------------------------------------
  60. //     TNetworkEventHandler::ProcessAnEvent
  61. // ---------------------------------------------------------------------------
  62. //    Process Network Event for this handler
  63.  
  64. void TNetworkEventHandler::ProcessEvents()
  65. {
  66.     TNetworkEvent*    aEvent;
  67.     TLifo        eventList;
  68.             
  69.     if(! fEventQueue.IsEmpty()){
  70.  
  71. // get head of event list
  72.         eventList.fHead = fEventQueue.StealList();
  73.         eventList.Reverse();
  74.         
  75. // Process each event on list    
  76.         while( aEvent = (TNetworkEvent*) eventList.Dequeue() )
  77.             {
  78.                     HandleEvent(aEvent);
  79.                     delete aEvent;
  80.                 }        
  81.         }
  82. }
  83.  
  84.  
  85. // ---------------------------------------------------------------------------
  86. //     TNetworkEventHandler::ScanEventHandlerQueue
  87. // ---------------------------------------------------------------------------
  88. //    Scan Network Event list looking for things to do
  89.  
  90. void TNetworkEventHandler::ScanEventHandlerQueue()
  91. {
  92.     TNetworkEventHandler *aTask;
  93.     
  94.     for (aTask =  (TNetworkEventHandler*) fgActiveList.GetFirst(); 
  95.           aTask ;
  96.           aTask = (TNetworkEventHandler*) aTask->Next())
  97.         {
  98.             aTask->ProcessEvents();
  99.         }            
  100.     
  101. }
  102.